<?php

namespace User\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Db\Adapter\Adapter as DbAdapter;
use User\Model\UserTable;

class UserController extends AbstractActionController
{
    
	protected $userTable;
	
	public function userAction()
    {
        return new ViewModel(array(
		'utilisateurs' => $this->getUserTable()->fetchAll(),
		));

//     	return new ViewModel(array(
//     	 		'utilisateurs' => $this->getUserTable()->getUser(2),
//     	 		));
    }
    
    public function getUserTable()
    {
    	if (!$this->userTable) {
    		$sm = $this->getServiceLocator();
    		$config = $sm->get('config');
    		$config = $config['db'];
    		$dbAdapter = new DbAdapter($config);
    		//return $dbAdapter;
    		$table = new UserTable($dbAdapter);
    		//$this->userTable = $sm->get($table);
    		$this->userTable = $table;
    	}
    	return $this->userTable;
    }
}

